import SelectUnit from '../component/SelectUnit';
import { login_way } from '../common/Function';

export function loginPage({Unit_ID, UnitUrl, UnitName, UserName, UnitUrl2,user,pass}) {          //更换账号
  const tpl = `
    <div class="top">
      <p>用户登录</p>
    </div>
    <div class="entry form">
      <p>单位：</p>
      <input type="text" id="choose" value="${UnitName}" />
      <a href="###" class="lick">选择单位</a>
      <p>用户登录：</p>
      <input type="text" id="user" value="${user ? user : ''}" />
      <input type="password" id="pass" />
      <a href="###" class="lostpassword">忘记密码？</a>
      <div class="prompt">
        <h2>温馨提示</h2>
        <p>请找发放账号密码的老师找回密码。</p>
        <a href="#">知道了</a>
      </div>
      <a class="btn login"  role="button">登 录</a>
    </div>
  `
  $('.right').html(tpl);
  
  loginPage_event(UnitUrl,UnitUrl2);
}



function loginPage_event(url,url2) {
  const prompt = document.getElementsByClassName("prompt")[0];
  const lostpass = document.getElementsByClassName("lostpassword")[0];
  const company = document.getElementById('choose');
  lostpass.onclick = function () {                       //显示忘记密码
      prompt.style.display = "block";
  }
  prompt.children[2].onclick = function () {              //取消忘记密码提示
      prompt.style.display = "none";
  }

  const lick = document.getElementsByClassName("lick")[0];
  lick.onclick = function () {                                 //单位选择
      SelectUnit.bindOk((data)=>{
        if(data){
          const {Unit_ID, UnitUrl, UnitName,UnitUrl2} = data;
          company.value = UnitName;
          company.dataset.id = Unit_ID;
          login_way(UnitUrl,UnitUrl2); // 登陆事件绑定
        }
      })
      SelectUnit.show();
  }

  login_way(url,url2); // 登陆事件绑定
}
